
package cn.pegasus.teamwork.sysconfig.service.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.iyizhan.teamwork.base.service.impl.BaseServiceImpl;
import cn.iyizhan.teamwork.base.util.PageObject;
import cn.pegasus.teamwork.sysconfig.entity.SysAppealMessage;
import cn.pegasus.teamwork.sysconfig.entity.SysConfigMessage;
import cn.pegasus.teamwork.sysconfig.mapper.SysAppealMessageMapper;
import cn.pegasus.teamwork.sysconfig.mapper.SysConfigMessageMapper;
import cn.pegasus.teamwork.sysconfig.service.SysAppealMessageService;
import cn.pegasus.teamwork.sysconfig.service.SysConfigMessageService;
/**
 * @author buyuer
 * @version 
 */
@Service
public class SysAppealMessageServiceImpl extends BaseServiceImpl<SysAppealMessage,SysAppealMessageMapper> implements
		SysAppealMessageService {
	Logger logger = Logger.getLogger(this.getClass());

	//注入当前dao对象
	@Autowired
	private SysAppealMessageMapper sysAppealMessageMapper;

	@Autowired
	private SysConfigMessageMapper sysConfigMessageMapper;
	@Autowired
	private SysConfigMessageService messageService;// 消息
	
	public SysAppealMessageServiceImpl() {
        setMapperClass(SysAppealMessageMapper.class, SysAppealMessage.class);
    }

	public List<SysAppealMessage> appealList() {
		
		return sysAppealMessageMapper.appealList();
	}

	
	@Override
	public PageObject<SysAppealMessage> getAppealPageList(Map<String, Object> map) {
		
		SysAppealMessage sysAppealMessage = M2O(map);
		// int totalData = sysAppealMessageMapper.getCount(sysAppealMessage);
//		PageHelper pageHelper = new PageHelper(0, map);
//		List<SysAppealMessage> list = sysAppealMessageMapper.pageQueryByObject(pageHelper.getMap());
//		PageObject<SysAppealMessage> pageObject = pageHelper.getPageObject();
//		pageObject.setDataList(list);
		return null;
	}

	public Map<String,Object> response(Map<String,Object> map) throws Exception {
		Map<String,Object> returnMap=new HashMap<String, Object>();
		Long id = Long.parseLong(map.get("id").toString());
		SysAppealMessage message = new SysAppealMessage();
		message.setId(id);
		message  = sysAppealMessageMapper.selectSingle(message);
		//0未处理1已处理
		message.setStatus(1);
		Date createDate = new Date();
		message.setProcessTime(createDate);
		sysAppealMessageMapper.updateByEntity(message);
		String responseMsg = map.get("msg")==null?"":map.get("msg").toString();
		SysConfigMessage sysConfigMessage = new SysConfigMessage(); 
		sysConfigMessage.setCreateTime(createDate);
		sysConfigMessage.setMsgContent("管理员反馈了您的问题,内容为:"+responseMsg);
		//由于不想改数据库，用此字段关联申诉表id
		sysConfigMessage.setMsgTitle("反馈通知");
		sysConfigMessage.setMsgType(6);
		sysConfigMessage.setMsgSendUserid(id);
		sysConfigMessage.setCurrType(1);
		//0未读1已读
		sysConfigMessage.setHasRead(0);
		sysConfigMessage.setMsgAcceptUserid(message.getUserId());
		sysConfigMessage.setMsgSendDate(new Date());
		sysConfigMessageMapper.insertByEntity(sysConfigMessage);
		//推送
//		messageService.pushMessage(sysConfigMessage.getId());
		returnMap.put("sysConfigMessage", sysConfigMessage);
		return returnMap;
	}
 
	public SysAppealMessage selectSingle(SysAppealMessage sam) {
		return sysAppealMessageMapper.selectSingle(sam);
	}
}
